import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path"; //这个 path 用到了上面安装的@types/node
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      AutoImport({
        //安装两行后你会发现在组件中不用再导入ref，reactive等
        imports: ["vue", "vue-router"],
        dts: "src/auto-import.js",
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src"), // @代替 src
      },
    },
    base: "/lea/",
    server: {
      host: "0.0.0.0",
      cors: true,
      port: 8088,
      open: false, //自动打开
      proxy: {
        "^/api": {
          target: env.VITE_BASE_URL, // 真实接口地址
          changeOrigin: true, // 允许跨域
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
    },
  };
});
